<!DOCTYPE html>
<html>
    <head lang="en">
        <meta charset="UTF-8">
        <title></title>
        <style>
        .ancestors *{
            display: block;
            border: 2px solid blueviolet;
            color:  blueviolet;
            padding: 5px;
            margin: 15px;
        }
        </style>
        <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js">
        </script>
        
        <script>
            $(document).ready(function(){
                $("span").parents("ul").css({"color":"red","border":"2px solid red"});
            });
        </script>
    </head>
    <body class="ancestors">body(great-great-grandparent)
        <div style="width:500px;">div (great-grandparent)
            <ul>
                ul (grandparent)
                    <span>span</span>
            </ul>
        </div>
        

    </body>
</html>